/*
 * MakaoView.java
 */
package makao;

import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JTable;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import makao.server.Server;

/**
 * The application's main frame.
 */
public class MakaoView extends FrameView
{

    private PlayerData playerData = new PlayerData(this);
    private CardsCache cardCacheFrame = new CardsCache(this);
    private JokerReplaceForm jockerReplaceForm = new JokerReplaceForm(this);
    private SuitFrame suitFrame = new SuitFrame(this);
    private TypeFrame typeFrame = new TypeFrame(this);
    private LogFrame logFrame = new LogFrame();
    private LoginFrame loginFrame = new LoginFrame();
    private PlayerAction playerAction = null;
    private Connection connection = null;
    private Clock clock;
    private Server server;

    public MakaoView(SingleFrameApplication app)
    {
        super(app);
        initComponents();
        presetClient();
        logFrame.setVisible(true);
        loginFrame.setMakaoView(this);
        cardsPanel.setEnabled(false);
    }

    private void presetClient()
    {
        cardsPanel.setPlayerData(playerData, this);
        tablePanel.setTable(playerData, this);
        infoPanel.setPlayerData(playerData, this);
        
        jTable.getColumnModel().getColumn(0).setHeaderValue("");
        jTable.getColumnModel().getColumn(1).setHeaderValue("Gracz");
        jTable.getColumnModel().getColumn(2).setHeaderValue("Pkt");
        jTable.getColumnModel().getColumn(3).setHeaderValue("Czeka");
        jTable.getColumnModel().getColumn(4).setHeaderValue("Karty");

        jTable.getColumnModel().getColumn(0).setMinWidth(30);
        jTable.getColumnModel().getColumn(0).setMaxWidth(30);
        jTable.getColumnModel().getColumn(1).setMinWidth(82);
        jTable.getColumnModel().getColumn(1).setMaxWidth(82);
        jTable.getColumnModel().getColumn(2).setMinWidth(43);
        jTable.getColumnModel().getColumn(2).setMaxWidth(43);
        jTable.getColumnModel().getColumn(3).setMinWidth(43);
        jTable.getColumnModel().getColumn(3).setMaxWidth(43);
        jTable.getColumnModel().getColumn(4).setMinWidth(43);
        jTable.getColumnModel().getColumn(4).setMaxWidth(43);

        clock = new Clock(jLabelClock);
        cardsPanel.setTable(tablePanel);
    }

    public PlayerData getPlayerData()
    {
        return playerData;
    }

    public JEditorPane getLogPane()
    {
        return logFrame.getEditorPane();
    }

    public TablePanel getTablePanel()
    {
        return tablePanel;
    }

    public InfoPanel getInfoPanel()
    {
        return infoPanel;
    }

    public CardsPanel getCardsPanel()
    {
        return cardsPanel;
    }

    public PlayerAction getPlayerAction()
    {
        return playerAction;
    }

    public CardsCache getCardCacheFrame()
    {
        return cardCacheFrame;
    }

    public Clock getClock()
    {
        return clock;
    }

    public SuitFrame getSuitFrame()
    {
        return suitFrame;
    }

    public TypeFrame getTypeFrame()
    {
        return typeFrame;
    }

    public JokerReplaceForm getJokerReplaceForm()
    {
        return jockerReplaceForm;
    }

    public JLabel getLabelTakeCards()
    {
        return jLabelTakeCards;
    }

    public JLabel getLabelTurnsWait()
    {
        return jLabelTurnWait;
    }
    
    public JLabel getLabelDemand()
    {
        return jLabelDemand;
    }

    public JTable getPlayersTable()
    {
        return jTable;
    }

    public void clearFinalConnection()
    {
        connection = null;
        playerAction = null;
        tablePanel.setEnabled(false);
    }
    
    public void startUpConnection(String ipAddress, String login)
    {
        if (ipAddress != null && login != null)
        {
            try
            {
                connection = new Connection(ipAddress, 9753, login, this.getLogPane(), this);
                playerAction = new PlayerAction(this, connection.getObjectOutputStream());
                playerData.setLogin(login);
            } catch (IOException ex)
            {
                logFrame.getEditorPane().setText(logFrame.getEditorPane().getText() + "BŁĄD LOGOWANIA!!!\nPrawdopodobnie zły adres serwera lub problem z połączeniem sieciowym\n");
                logFrame.setVisible(true);
            }
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        cardsBackgroundPanel = new makao.CardsBackgroundPanel();
        jScrollPaneCards = new javax.swing.JScrollPane();
        cardsPanel = new makao.CardsPanel();
        infoPanel = new makao.InfoPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable = new javax.swing.JTable();
        jLabelClock = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabelDemand = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabelTakeCards = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabelTurnWait = new javax.swing.JLabel();
        tablePanel = new makao.TablePanel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(makao.MakaoApp.class).getContext().getResourceMap(MakaoView.class);
        mainPanel.setBackground(resourceMap.getColor("mainPanel.background")); // NOI18N
        mainPanel.setName("mainPanel"); // NOI18N

        cardsBackgroundPanel.setName("cardsBackgroundPanel"); // NOI18N

        jScrollPaneCards.setBorder(null);
        jScrollPaneCards.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        jScrollPaneCards.setName("jScrollPaneCards"); // NOI18N

        cardsPanel.setBackground(resourceMap.getColor("cardsPanel.background")); // NOI18N
        cardsPanel.setName("cardsPanel"); // NOI18N
        cardsPanel.setPreferredSize(new java.awt.Dimension(698, 150));
        cardsPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cardsPanelMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout cardsPanelLayout = new javax.swing.GroupLayout(cardsPanel);
        cardsPanel.setLayout(cardsPanelLayout);
        cardsPanelLayout.setHorizontalGroup(
            cardsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 714, Short.MAX_VALUE)
        );
        cardsPanelLayout.setVerticalGroup(
            cardsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 150, Short.MAX_VALUE)
        );

        jScrollPaneCards.setViewportView(cardsPanel);

        javax.swing.GroupLayout cardsBackgroundPanelLayout = new javax.swing.GroupLayout(cardsBackgroundPanel);
        cardsBackgroundPanel.setLayout(cardsBackgroundPanelLayout);
        cardsBackgroundPanelLayout.setHorizontalGroup(
            cardsBackgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cardsBackgroundPanelLayout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jScrollPaneCards, javax.swing.GroupLayout.DEFAULT_SIZE, 714, Short.MAX_VALUE)
                .addGap(36, 36, 36))
        );
        cardsBackgroundPanelLayout.setVerticalGroup(
            cardsBackgroundPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cardsBackgroundPanelLayout.createSequentialGroup()
                .addContainerGap(21, Short.MAX_VALUE)
                .addComponent(jScrollPaneCards, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
        );

        infoPanel.setName("infoPanel"); // NOI18N

        jScrollPane2.setBackground(resourceMap.getColor("jScrollPane2.background")); // NOI18N
        jScrollPane2.setBorder(new javax.swing.border.LineBorder(resourceMap.getColor("jScrollPane2.border.lineColor"), 7, true)); // NOI18N
        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTable.setBackground(resourceMap.getColor("jTable.background")); // NOI18N
        jTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                " ", "Gracz", "Pkt", "Czeka", "Karty"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jTable.setGridColor(resourceMap.getColor("jTable.gridColor")); // NOI18N
        jTable.setName("jTable"); // NOI18N
        jTable.setSelectionBackground(resourceMap.getColor("jTable.selectionBackground")); // NOI18N
        jScrollPane2.setViewportView(jTable);
        jTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable.columnModel.title0")); // NOI18N
        jTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable.columnModel.title1")); // NOI18N
        jTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable.columnModel.title2")); // NOI18N
        jTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable.columnModel.title3")); // NOI18N

        jLabelClock.setFont(resourceMap.getFont("jLabelClock.font")); // NOI18N
        jLabelClock.setForeground(resourceMap.getColor("jLabelClock.foreground")); // NOI18N
        jLabelClock.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelClock.setText(resourceMap.getString("jLabelClock.text")); // NOI18N
        jLabelClock.setToolTipText(resourceMap.getString("jLabelClock.toolTipText")); // NOI18N
        jLabelClock.setName("jLabelClock"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel1.setIcon(resourceMap.getIcon("jLabel1.icon")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setFocusCycleRoot(true);
        jLabel1.setName("jLabel1"); // NOI18N

        jLabelDemand.setFont(resourceMap.getFont("jLabelDemand.font")); // NOI18N
        jLabelDemand.setForeground(resourceMap.getColor("jLabelDemand.foreground")); // NOI18N
        jLabelDemand.setText(resourceMap.getString("jLabelDemand.text")); // NOI18N
        jLabelDemand.setName("jLabelDemand"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setForeground(resourceMap.getColor("jLabel3.foreground")); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel3.setIcon(resourceMap.getIcon("jLabel3.icon")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabelTakeCards.setFont(resourceMap.getFont("jLabelTakeCards.font")); // NOI18N
        jLabelTakeCards.setForeground(resourceMap.getColor("jLabelTakeCards.foreground")); // NOI18N
        jLabelTakeCards.setText(resourceMap.getString("jLabelTakeCards.text")); // NOI18N
        jLabelTakeCards.setName("jLabelTakeCards"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setForeground(resourceMap.getColor("jLabel2.foreground")); // NOI18N
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel2.setIcon(resourceMap.getIcon("jLabel2.icon")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabelTurnWait.setFont(resourceMap.getFont("jLabelTurnWait.font")); // NOI18N
        jLabelTurnWait.setForeground(resourceMap.getColor("jLabelTurnWait.foreground")); // NOI18N
        jLabelTurnWait.setText(resourceMap.getString("jLabelTurnWait.text")); // NOI18N
        jLabelTurnWait.setName("jLabelTurnWait"); // NOI18N

        javax.swing.GroupLayout infoPanelLayout = new javax.swing.GroupLayout(infoPanel);
        infoPanel.setLayout(infoPanelLayout);
        infoPanelLayout.setHorizontalGroup(
            infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, infoPanelLayout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(infoPanelLayout.createSequentialGroup()
                        .addGap(13, 13, 13)
                        .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabelDemand, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabelTakeCards, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabelTurnWait, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE))
                        .addContainerGap(25, Short.MAX_VALUE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGroup(infoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelClock, javax.swing.GroupLayout.DEFAULT_SIZE, 286, Short.MAX_VALUE))
        );
        infoPanelLayout.setVerticalGroup(
            infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, infoPanelLayout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabelClock, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelDemand, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelTakeCards, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(infoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelTurnWait, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 156, Short.MAX_VALUE)
                .addGap(20, 20, 20))
        );

        tablePanel.setEnabled(false);
        tablePanel.setName("tablePanel"); // NOI18N
        tablePanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tablePanelMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout tablePanelLayout = new javax.swing.GroupLayout(tablePanel);
        tablePanel.setLayout(tablePanelLayout);
        tablePanelLayout.setHorizontalGroup(
            tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 477, Short.MAX_VALUE)
        );
        tablePanelLayout.setVerticalGroup(
            tablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 401, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(infoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tablePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(cardsBackgroundPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(0, 0, 0)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tablePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(infoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cardsBackgroundPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem1);

        jMenuItem2.setText(resourceMap.getString("jMenuItem2.text")); // NOI18N
        jMenuItem2.setName("jMenuItem2"); // NOI18N
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem2);

        jMenuItem4.setText(resourceMap.getString("jMenuItem4.text")); // NOI18N
        jMenuItem4.setName("jMenuItem4"); // NOI18N
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem4);

        jMenuItem3.setText(resourceMap.getString("jMenuItem3.text")); // NOI18N
        jMenuItem3.setName("jMenuItem3"); // NOI18N
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        fileMenu.add(jMenuItem3);

        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(makao.MakaoApp.class).getContext().getActionMap(MakaoView.class, this);
        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setText(resourceMap.getString("aboutMenuItem.text")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aboutMenuItemActionPerformed(evt);
            }
        });
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    private void cardsPanelMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_cardsPanelMouseClicked
    {//GEN-HEADEREND:event_cardsPanelMouseClicked

        if (cardsPanel.isEnabled())
        {
            if (evt.getClickCount() == 2 && !evt.isConsumed())
            {
                cardsPanel.chooseCard(evt.getX(), evt.getY());
                evt.consume();
            } else
            {
                if (evt.getClickCount() == 1 && !evt.isConsumed())
                {
                    cardsPanel.selectCard(evt.getX(), evt.getY());
                    evt.consume();
                }
            }
        }

    }//GEN-LAST:event_cardsPanelMouseClicked

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jMenuItem1ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
        server = new Server();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void tablePanelMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_tablePanelMouseClicked
    {//GEN-HEADEREND:event_tablePanelMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount() == 1 && tablePanel.isEnabled())
        {
            tablePanel.checkTableClick(evt.getX(), evt.getY());
        }
    }//GEN-LAST:event_tablePanelMouseClicked

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jMenuItem2ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
        if (connection == null)
        {
            logFrame.getEditorPane().setText("");

            loginFrame.setLocation(this.getFrame().getLocationOnScreen().x + (this.getFrame().getWidth() / 2) - 195,
                    this.getFrame().getLocationOnScreen().y + (this.getFrame().getHeight() / 2) - 75);
            loginFrame.setVisible(true);
            loginFrame.setFocus();
            tablePanel.setEnabled(false);
            cardsPanel.setEnabled(false);
        } else
        {
            logFrame.getEditorPane().setText(logFrame.getEditorPane().getText() + "Jesteś już zalogowany!\n");
        }
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_exitMenuItemActionPerformed
    {//GEN-HEADEREND:event_exitMenuItemActionPerformed
        if (connection != null)
        {
            connection.disconnect();
        }
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jMenuItem3ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem3ActionPerformed
        if (connection != null)
        {
            connection.disconnect();
            logFrame.getEditorPane().setText(logFrame.getEditorPane().getText() + "Wylogowano poprawnie!\n Zakończono połączenie poprawnie!\n");
        } else
        {
            logFrame.getEditorPane().setText(logFrame.getEditorPane().getText() + "Nie jesteś zalogowany na żadnym serwerze!\n");
        }
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_aboutMenuItemActionPerformed
    {//GEN-HEADEREND:event_aboutMenuItemActionPerformed
        logFrame.setVisible(true);
    }//GEN-LAST:event_aboutMenuItemActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jMenuItem4ActionPerformed
    {//GEN-HEADEREND:event_jMenuItem4ActionPerformed
        if (connection != null)
        {
            playerData.clearPlayerDataToNextgame();
            logFrame.getEditorPane().setText(logFrame.getEditorPane().getText() + "Wylogowano poprawnie!\n");
        } else
        {
            logFrame.getEditorPane().setText(logFrame.getEditorPane().getText() + "Nie jesteś zalogowany na żadnym serwerze!\n");
        }
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private makao.CardsBackgroundPanel cardsBackgroundPanel;
    private makao.CardsPanel cardsPanel;
    private makao.InfoPanel infoPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabelClock;
    private javax.swing.JLabel jLabelDemand;
    private javax.swing.JLabel jLabelTakeCards;
    private javax.swing.JLabel jLabelTurnWait;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPaneCards;
    private javax.swing.JTable jTable;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private makao.TablePanel tablePanel;
    // End of variables declaration//GEN-END:variables
}
